package com.smartfast4j.backend.modules.sys.security.shiro;

import org.apache.shiro.spring.web.ShiroFilterFactoryBean;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * shiro 扩展之动态加载权限
 * Created by gacl on 2017/10/10.
 */
public class MyShiroFilterFactoryBean extends ShiroFilterFactoryBean {

    /**
     * 动态加载权限，初始化的时候会加载
     * @param filterChainDefinitionMap
     */
    @Override
    public void setFilterChainDefinitionMap(Map<String, String> filterChainDefinitionMap) {
        Map<String,String> filterMap=new LinkedHashMap<>();//这里需要使用有序的LinkedHashMap
        //配置资源访问权限，注意URL Pattern里用到的是两颗星,这样才能实现任意层次的全匹配
        filterMap.put("/","anon");
        filterMap.put("/static/**","anon");
        filterMap.put("/sys/login","anon");
        filterMap.put("/captcha.jpg","anon");
        filterMap.put("/sys/tool/getRsaPublicKey","anon");
        filterMap.put("/sys/tool/clearShiroCachedAuthenticationInfo","anon");
        filterMap.put("/sys/tool/clearCacheInfo","anon");
        filterMap.put("/sys/tool/updatePermission","anon");
        filterMap.put("/sys/sysUser/**","permission[sys:user:list1,sys:user:info1]");
        filterMap.put("/sys/**","login");
        super.setFilterChainDefinitionMap(filterMap);
    }
}
